package com.lanxin.oa.approve.dao;

import com.lanxin.base.BaseDaoImpl;
import com.lanxin.bean.LcFlow;
import com.lanxin.util.PageBean;
import org.springframework.stereotype.Repository;

@Repository
public class ApproveDaoImpl extends BaseDaoImpl implements ApproveDao {
    @Override
    public PageBean<LcFlow> selectApprovePage(Integer page, Integer pageSize, LcFlow flow,String docType1) {
        if (page==null){
            page = 1;
        }
        if(pageSize == null){
            pageSize = 5;
        }
        String hql=("from LcFlow l where 1=1");
        if(flow.getFlowName()!=null && !"".equals(flow.getFlowName())){
            hql=hql+" and l.flowName like '%"+flow.getFlowName()+"%'";
        }
        if(docType1!=null && !"".equals(docType1)){
            hql=hql+" and l.docType='"+docType1+"'";
        }
        return super.pageFenYE(hql, page, pageSize);
    }

    @Override
    public LcFlow selectLcFlowByName(String flowName, Integer oid) {

        String hql = "from LcFlow l where l.flowName='" + flowName + "' ";
        LcFlow flow = null;
        if (oid != null) {
            hql = hql + " and l.oid=" + oid;
            flow = (LcFlow) selectByHQL(hql);
            if (flow != null) {
                return null;
            }
            flow = (LcFlow) selectByHQL("from LcFlow l where l.flowName='"+ flowName +"'");
            if (flow == null) {
                return null;
            }
        } else {
            return (LcFlow) selectByHQL(hql);
        }
        return flow;

    }

    @Override
    public LcFlow findFlowInfo(Integer oid) {
        return (LcFlow) selectByHQL("from LcFlow f  where f.oid="+oid);
    }
}
